package com.vagavaga.tcpt;

import java.io.IOException;
import java.nio.ByteBuffer;

/**
 * All connections served by {@link ITransportServer} implement this interface.
 * 
 * @author river
 * 
 */
public interface IConnection {

    /**
     * Attach user defined object to connection. Much like you can attach object
     * to raw selector.
     * 
     * @param o
     *        Object to attach.
     */
    void attach(Object o);

    /**
     * Detatches object from this connection. It has same effect as calling
     * <code>IConnection.attach(null);</code>.
     * 
     */
    void detatch();
    
    /**
     * Returns object attached to this connection.
     * @return object attached to this connection or null.
     */
    Object attachment();

    /**
     * Sends data over this connection.
     * @param buffer ByteBuffer containing data to send.
     * @throws IOException if exception occures during sending.
     */
    void send(ByteBuffer buffer) throws IOException;

    /**
     * Close this connection.
     * @throws IOException
     */
    void close() throws IOException;
}
